import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import { payWayList } from './api';
import { airportList } from '@apps/ant-bus/src/views/business/airport/data/api';
import { xunLianPayParamList } from '@apps/ant-bus/src/views/business/payset/xunlianPayparam/api';
import { yinLianPayParamList } from '@apps/ant-bus/src/views/business/payset/yinlianPayparam/api';
import { companyList } from '@apps/ant-bus/src/views/business/companyManage/company/data/api';
import { RenderType } from '@pkg/setting';
import { employeeList } from '@apps/ant-bus/src/views/business/employeeManage/employee/data/api';
import { employeeServerList } from '@apps/ant-bus/src/views/business/employeeManage/employeeserver/data/api';

export const columns: BasicColumn[] = [
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 100,
    align: 'center',
  },
  {
    title: '单次商品名称',
    dataIndex: 'goodsName',
    width: 150,
    align: 'center',
  },
  {
    title: '地区',
    dataIndex: 'airportName',
    width: 150,
    align: 'center',
  },
  {
    title: '次数',
    dataIndex: 'goodsNum',
    width: 100,
    align: 'center',
  },
  {
    title: '销售姓名',
    dataIndex: 'employeeName',
    width: 100,
    align: 'center',
  },
  {
    title: '合作企业',
    dataIndex: 'companyName',
    width: 150,
    align: 'center',
  },
  {
    title: '来源',
    dataIndex: 'sourceType',
    width: 120,
    dictData: [
      { label: '扫码注册', value: 1 },
      { label: '公众号购买', value: 2 },
      { label: '销售新增', value: 3 },
      { label: '后台新增', value: 4 },
      { label: '后台导入', value: 5 },
      { label: '礼品卡接收', value: 6 },
      { label: '后台批量生成', value: 7 },
      { label: '销售赠送', value: 8 },
      { label: '代理商下单', value: 9 },
      { label: '企业下单', value: 10 },
      { label: '后台券码生成', value: 11 },
      { label: '电子金兑换', value: 12 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '金额',
    dataIndex: 'payAmount',
    width: 100,
    align: 'center',
  },
  {
    title: '收款方式',
    dataIndex: 'paywayName',
    width: 150,
    align: 'center',
  },
  {
    title: '微信支付Id',
    dataIndex: 'payInfoId',
    width: 200,
    align: 'center',
  },
  {
    title: '退款状态',
    dataIndex: 'refundState',
    width: 100,
    align: 'center',
    dictData: [
      { label: '未申请', value: 0 },
      { label: '申请中', value: 1 },
      { label: '已取消', value: 2 },
      { label: '已退款', value: 3 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '使用状态',
    dataIndex: 'useState',
    width: 120,
    align: 'center',
    dictData: [
      { label: '未使用', value: 1 },
      { label: '已使用', value: 2 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '使用时间',
    dataIndex: 'checkDate',
    width: 120,
    align: 'center',
  },
  {
    title: '时间',
    dataIndex: 'createTime',
    width: 150,
    align: 'center',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'mainAccount',
    label: '用户账号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'userName',
    label: '姓名',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'mobile',
    label: '手机号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'quMaUserName',
    label: '券码姓名',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'quMaUserMobile',
    label: '券码手机号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'goodsName',
    label: '商品名称',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'qrCode',
    label: '券号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'employeeName',
    label: '销售',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'useState',
    label: '使用状态',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '未使用', value: 1 },
        { label: '已使用', value: 2 },
      ],
    },
  },
  {
    field: 'refundState',
    label: '退款状态',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '未申请', value: 0 },
        { label: '申请中', value: 1 },
        { label: '已取消', value: 2 },
        { label: '已退款', value: 3 },
      ],
    },
  },
  {
    field: 'payType',
    label: '收款方式',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: ({ formActionType, formModel }) => {
      return {
        options: [
          { label: '全部', value: '' },
          { label: '讯联微信', value: 'PAY_WX' },
          { label: '银联微信', value: 'PAY_WX_YINLIAN' },
          { label: '农业银行微信', value: 'PAY_WX_NONGYE' },
          { label: '富友微信', value: 'PAY_WX_FUIOU' },
          { label: '富友微信小程序', value: 'PAY_WX_FUIOU_MINI' },
          { label: '交通银行微信', value: 'PAY_WX_JIAOTONG' },
          { label: '线下支付', value: 'PAY_UNDERLINE' },
          { label: '扫码支付', value: 'PAY_QRCODE' },
          { label: '电子金余额支付', value: 'PAY_ELEAMOUNT' },
        ],
        onChange: payType => {
          console.info('payType', payType);
          const { updateSchema } = formActionType;
          //所属部门修改后更新负责部门下拉框数据
          let componentProps = {};
          if (payType == 'PAY_WX' || payType == 'PAY_QRCODE') {
            componentProps = {
              api: xunLianPayParamList,
              labelField: 'paramName',
              valueField: 'xunlianPayparamId',
              immediate: true,
              showSearch: true,
            };
          }
          if (payType == 'PAY_WX_YINLIAN') {
            componentProps = {
              api: yinLianPayParamList,
              labelField: 'yinlianPayName',
              valueField: 'yinlianpayparamId',
              immediate: true,
              showSearch: true,
            };
          }
          if (payType == 'PAY_UNDERLINE') {
            componentProps = {
              api: payWayList,
              labelField: 'paywayName',
              valueField: 'paywayId',
              immediate: true,
              showSearch: true,
            };
          }
          updateSchema([
            {
              field: 'targetPayParamId',
              componentProps: componentProps,
            },
          ]);
          formModel.targetPayParamId = null;
        },
      };
    },
  },
  {
    field: 'targetPayParamId',
    label: '支付通道',
    component: 'ApiSelect',
    colProps: { span: 4 },
    required: false,
    componentProps: {},
  },
  {
    field: 'payInfoId',
    label: '支付Id',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'airportId',
    label: '地区',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: airportList,
      labelField: 'airportName',
      valueField: 'airportId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    field: 'sourceType',
    label: '来源',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '扫码注册', value: 1 },
        { label: '公众号购买', value: 2 },
        { label: '销售新增', value: 3 },
        { label: '后台新增', value: 4 },
        { label: '后台导入', value: 5 },
        { label: '礼品卡接收', value: 6 },
        { label: '后台批量生成', value: 7 },
        { label: '销售赠送', value: 8 },
        { label: '代理商下单', value: 9 },
        { label: '企业下单', value: 10 },
        { label: '后台券码生成', value: 11 },
      ],
    },
  },
  {
    field: 'companyId',
    label: '合作企业',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: companyList,
      labelField: 'companyName',
      valueField: 'companyId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    field: 'startDate',
    label: '开始日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'endDate',
    label: '结束日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
];

export const useCheckFormSchema: FormSchema[] = [
  {
    label: '用户物品Id',
    field: 'userGoodsId',
    component: 'Input',
    show: false,
    required: true,
  },
  {
    label: '目标Id',
    field: 'goodsId',
    component: 'Input',
    show: false,
    required: true,
  },
  {
    label: '核销账号',
    field: 'employeeId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: employeeList,
        params: { handlerName: 'busEmployeeListHandler', targetId: formModel.goodsId },
        labelField: 'employeeName',
        valueField: 'employeeId',
        immediate: false,
        showSearch: true,
        onChange: employeeId => {
          formModel.serverId = null;
        },
      };
    },
  },
  {
    label: '核销服务',
    field: 'serverId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: employeeServerList,
        params: { employeeId: formModel.employeeId, serverType: 2 },
        labelField: 'serverName',
        valueField: 'serverId',
        immediate: false,
        showSearch: true,
        onChange: employeeId => {},
      };
    },
  },
  {
    label: '使用时间',
    field: 'useDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      format: 'YYYY-MM-DD HH:mm:ss',
    },
  },
  {
    label: '核验备注',
    field: 'useCheckRemark',
    component: 'InputTextArea',
    required: false,
  },
];
